package com.apex.aolonfitdemo.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


import com.apex.aolonfit.AolonFitManager;
import com.apex.aolonfitdemo.R;
import com.apex.aolonfitdemo.databinding.ActivityPushInfoBinding;
import com.apex.aolonfitdemo.dialog.WaitingDialog;
import com.apex.ax_bluetooth.callback.GeneralCallback;
import com.apex.ax_bluetooth.core.EABleManager;
import com.apex.ax_bluetooth.enumeration.EABleConnectState;
import com.apex.ax_bluetooth.model.EABleSocialContact;
import com.cyber.bridge.module.bean.AppNotifyEntity;
import com.cyber.bridge.module.listener.OnCyberNotifyListener;

import java.util.Calendar;


public class PushInfoActivity extends AppCompatActivity {

    private WaitingDialog waitingDialog;

    private Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0x40) {
                if (waitingDialog != null) {
                    if (waitingDialog.isShowing()) {
                        waitingDialog.dismiss();
                    }
                }
                Toast.makeText(PushInfoActivity.this, getString(R.string.push_successful), Toast.LENGTH_SHORT).show();
            } else if (msg.what == 0x41) {
                if (waitingDialog != null) {
                    if (waitingDialog.isShowing()) {
                        waitingDialog.dismiss();
                    }
                }
                Toast.makeText(PushInfoActivity.this, getString(R.string.push_failed), Toast.LENGTH_SHORT).show();
            }
        }
    };
    ActivityPushInfoBinding activityPushInfoBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityPushInfoBinding = ActivityPushInfoBinding.inflate(getLayoutInflater());
        setContentView(activityPushInfoBinding.getRoot());
        activityPushInfoBinding.tool.setNavigationIcon(R.mipmap.exit_page);
        setSupportActionBar(activityPushInfoBinding.tool);
        getSupportActionBar().setTitle(null);
        activityPushInfoBinding.tool.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        AolonFitManager.getInstance().setOnNotifyListener(new OnCyberNotifyListener() {
            @Override
            public void sendAppNotify(boolean b) {
                if (mHandler != null) {
                    mHandler.sendEmptyMessage(b ? 0x40 : 0x41);
                }
            }

            @Override
            public void sendSMSNotify(boolean b) {

            }

            @Override
            public void sendCallInNotify(boolean b) {

            }
        });
        activityPushInfoBinding.pushFaceBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (waitingDialog == null) {
                    waitingDialog = new WaitingDialog(PushInfoActivity.this);
                }
                if (!waitingDialog.isShowing()) {
                    waitingDialog.show();
                }
                AolonFitManager.getInstance().sendAppNotify(new AppNotifyEntity(activityPushInfoBinding.faceBookContent.getText().toString(), "com.facebook.katana", activityPushInfoBinding.faceBookTitle.getText().toString()));

            }
        });


    }

    @Override
    protected void onDestroy() {

        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
            mHandler = null;
        }
        if (waitingDialog != null) {
            waitingDialog.dismiss();
            waitingDialog = null;
        }

        super.onDestroy();
    }
}
